
extern "C" {
    fn __errno_location() -> *mut i32;
    fn malloc(_: u64) -> *mut ();
    fn calloc(_: u64, _: u64) -> *mut ();
    fn free(_: *mut ());
    fn memcpy(_: *mut (), _: *const (), _: u64) -> *mut ();
    fn memset(_: *mut (), _: i32, _: u64) -> *mut ();
    fn explicit_bzero(__s: *mut (), __n: size_t);
    fn getpagesize() -> i32;
}
pub type size_t = u64;
#[no_mangle]
pub extern "C" fn recallocarray(
    mut ptr: *mut (),
    mut oldnmemb: size_t,
    mut newnmemb: size_t,
    mut size: size_t,
) -> *mut () {
    let mut oldsize: size_t = 0;
    let mut newsize: size_t = 0;
    let mut newptr: *mut () = std::ptr::null_mut::<()>();
    if ptr.is_null() {
        return unsafe { calloc(newnmemb, size) };
    }
    if (newnmemb
        >= (1 as i32 as size_t)
            << (::core::mem::size_of::<size_t>() as u64).wrapping_mul(4 as i32 as u64)
        || size
            >= (1 as i32 as size_t)
                << (::core::mem::size_of::<size_t>() as u64).wrapping_mul(4 as i32 as u64))
        && newnmemb > 0 as u64
        && (18446744073709551615 as u64).wrapping_div(newnmemb) < size
    {
        (unsafe { *__errno_location() = 12 });
        return std::ptr::null_mut::<()>();
    }
    newsize = newnmemb.wrapping_mul(size);
    if (oldnmemb
        >= (1 as i32 as size_t)
            << (::core::mem::size_of::<size_t>() as u64).wrapping_mul(4 as i32 as u64)
        || size
            >= (1 as i32 as size_t)
                << (::core::mem::size_of::<size_t>() as u64).wrapping_mul(4 as i32 as u64))
        && oldnmemb > 0 as u64
        && (18446744073709551615 as u64).wrapping_div(oldnmemb) < size
    {
        (unsafe { *__errno_location() = 22 });
        return std::ptr::null_mut::<()>();
    }
    oldsize = oldnmemb.wrapping_mul(size);
    if newsize <= oldsize {
        let mut d: size_t = oldsize.wrapping_sub(newsize);
        if d < oldsize.wrapping_div(2 as i32 as u64) && d < (unsafe { getpagesize() }) as size_t {
            (unsafe {
                memset(
                    (ptr as *mut i8).offset(newsize as isize) as *mut (), 0,
                    d,
                )
            });
            return ptr;
        }
    }
    newptr = unsafe { malloc(newsize) };
    if newptr.is_null() {
        return std::ptr::null_mut::<()>();
    }
    if newsize > oldsize {
        (unsafe { memcpy(newptr, ptr, oldsize) });
        (unsafe {
            memset(
                (newptr as *mut i8).offset(oldsize as isize) as *mut (), 0,
                newsize.wrapping_sub(oldsize),
            )
        });
    } else {
        (unsafe { memcpy(newptr, ptr, newsize) });
    }
    (unsafe { explicit_bzero(ptr, oldsize) });
    (unsafe { free(ptr) });
    return newptr;
}
